<?php
namespace app\home\controller;

use app\home\model\UserModel;
use think\Controller;
use think\Request;
use think\db;

class User extends Controller
{
    public function __construct(Request $request = null)
    {
        $result = $this->_getBid();
        if(!$result){
            $this->success('未登录', 'index/login');
        }
    }
   /**
    * 用户类
    *
    */
    public function index(){
        $bid = $this->_getBid();
        $result = UserModel::instance()->userlist($bid);
        foreach($result as $k=>$v){
            $data = [];
            $data = $v;
            $v['regtime'] == 0 ? $data['regtime'] = '' :$data['regtime'] = date('Y-m-d H:i:s',$v['regtime']);
            $result->offsetSet($k,$data);
        }
        return view('user/index',['data'=>$result]);

    }
    /**
     * 详情
     */
    public function show(Request $request){
        $id = $request->get('id');
        $details = UserModel::instance()->details($id);
        $details['login_status'] = 0 ? $details['login_status'] = '未登录' : $details['login_status'] = '登录';
        $details['sex'] = 1 ? $details['sex'] = '男' : $details['sex'] = '女';
        $details['regtime'] == 0 ? $details['regtime'] = '' : $details['regtime'] = date('Y-m-d H:i:s',$details['regtime']);
        return view('user/show',['data'=>$details]);
    }
    public function indexs(){
        $bid = $this->_getBid();
        $result = db('user')
            ->where('looktime','>=', time()-(3600*24))
            ->field('nickname,uid,phone,sex,looktime,address')
            ->order('looktime desc')
            ->paginate(15);
//        var_dump($result);exit();
//        foreach($result as $k=>$v){
//            $data = [];
//            $data = $v;
//            $v['regtime'] == 0 ? $data['regtime'] = '' :$data['regtime'] = date('Y-m-d H:i:s',$v['regtime']);
//            $result->offsetSet($k,$data);
//        }
        return view('user/indexs',['data'=>$result]);
    }
    /**
     *意见反馈
     */
    public function fankui(Request $request){
        $bid = $this->_getBid();
        $result=Db('fankui')->alias('f')->join('user u','u.uid = f.uid')->field('f.*,u.nickname,u.phone,u.qqnum')->where(['f.bid'=>$bid])->select();
        foreach($result as $k=>$v) {
            $result[$k]['createtime'] = date('Y-m-d H:i:m', $result[$k]['createtime']);
        }
        return view('user/fankui',['data'=>$result]);
    }
    /**
     *删除意见反馈
     */
    public function deletes($id){
        $result=Db('fankui')->where(['id'=>$id])->delete();
        if($result){
            echo 1;
        }else{
            echo 0;
        }
    }
}
